home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr14 / dndprogs.zip / DICE < prev    next >
Text File  |  1993-04-01  |  4KB  |  126 lines

  1. Path: pdxgate!ogicse!mintaka!think.com!snorkelwacker.mit.edu!stanford.edu!agate!darkstar!ucscb.UCSC.EDU!iago
  2. From: iago@ucscb.UCSC.EDU (tsource)
  3. Newsgroups: rec.games.frp
  4. Subject: dice curve plote 1.0
  5. Message-ID: <14123@darkstar.ucsc.edu>
  6. Date: 4 Apr 91 10:46:25 GMT
  7. Sender: usenet@darkstar.ucsc.edu
  8. Organization: University of California, Santa Cruz; Open Access Computing
  9. Lines: 113
  10. Posted: Thu Apr  4 02:46:25 1991
  11. Warning: Poster tried to forge this article as  tsource@ucscb.ucsc.edu (tsource)
  12.  
  13.  
  14. Here is something someone might find useful 
  15. FAST NOTE: the code is not the best of style (it works
  16. though) since I wrote in the wee morning hours after a
  17. party
  18. ------------------------- CUT HERE ---------------------------
  19. Ever wanted to get data on the curve of a specfic fundimental die roll
  20. i.e. XdY with no modifers.  Well maybe dice plot 1.0 (actually called dice
  21. when called) can shed some light on the matter.  It will ask what your 
  22. fundtimental die is (i.e. XdY) and how many samples (i.e. how times to
  23. roll the fundtimental die).  Also if you want to put it in a file
  24. if so then it will ask for the file name.  For example
  25. the following input will produce this output to the screen
  26. Input:
  27. How many times rolled and how many dice (xdy): 3d6
  28. How many samples: 20000
  29. Do you want a outfile(y or n): n
  30. Output:
  31. This is the result of 20000 rolls of 3d6
  32. #    % tot    % lower    % higher    number    graph
  33. 3    0.495    0.000    99.505        99    *
  34. 4    1.265    0.495    98.240        253    **
  35. 5    2.995    1.760    95.245        599    ***
  36. 6    4.435    4.755    90.810        887    *****
  37. 7    7.010    9.190    83.800        1402    ********
  38. 8    9.750    16.200    74.050        1950    **********
  39. 9    11.385    25.950    62.665        2277    ************
  40. 10    12.295    37.335    50.370        2459    *************
  41. 11    12.890    49.630    37.480        2578    *************
  42. 12    11.490    62.520    25.990        2298    ************
  43. 13    10.070    74.010    15.920        2014    ***********
  44. 14    6.710    84.080    9.210        1342    *******
  45. 15    4.690    90.790    4.520        938    *****
  46. 16    2.715    95.480    1.805        543    ***
  47. 17    1.375    98.195    0.430        275    **
  48. 18    0.430    99.570    -0.000        86    *
  49.  
  50. Other then that I should warn you that for 1dy it often gives bad high and low
  51. %'s.  Also sometimes you will get -0% the problem is it truncates but the
  52. truncating so far has no noticable effect except for this wierd percentage.
  53.  
  54. Other then that if you have bug reports, complaiments, and or flames send them
  55. to aryeh@cash.ucsc.edu or bfwong@ocf.berkeley.edu
  56.  
  57. Except for that here is a list of what I want to add to further versions.
  58.  
  59.     -- complex dice systems
  60.     -- fix 1dy bug
  61.     -- add calced stadard devations
  62. ------------------------ CUT HERE ------------------------------------
  63. #include <stdio.h>
  64.  
  65. main()
  66. {
  67.     long i,j,k,*res;
  68.     double per,minper,maxper,strange_per;
  69.     int x,y;
  70.     long MAXROLLS;
  71.     char c[80],filename[80];
  72.     FILE *fp;
  73.  
  74.     printf("Numer of times rolled and # of dice (xdy) for each:");
  75.     scanf("%dd%d",&y,&x);
  76.     printf("How many samples should I have:");
  77.     scanf("%d",&MAXROLLS);
  78.     printf("Do you want a output file(y or n):");
  79.     scanf("%s",c);
  80.     if(strcmp(c,"y")==0){
  81.         printf("What outfile do you want:");
  82.         scanf("%s",filename);
  83.         fp=fopen(filename,"w");
  84.     }
  85.        else fp=stdout;
  86.     res=(int *) malloc(((x*y)+1)*sizeof(long));
  87.     for(j=y;j<x+y;j++) res[j]=0;
  88.     for(j=0;j<=MAXROLLS-1;j++){
  89.         i=0;
  90.         for(k=0;k<y;k++) i+=(int) (random()%x)+1;
  91.         res[i]++;
  92.     }
  93.     fprintf(fp,"This is the result of %d rolls of %dd%d\n",MAXROLLS,y,x);
  94.     fprintf(fp,"#\t%% tot\t%% lower\t%% higher\tnumber\tgraph\n");
  95.     /* we need to keep track of this to have maxper, minper and per add up 
  96.     to 100 and be 0 at the extremes */
  97.     strange_per=res[(x*y)+1];
  98.     strange_per/=MAXROLLS;
  99.     strange_per*=100;
  100.     maxper=100+strange_per;
  101.     /* since the actually workings of max and min will zero them to their
  102.     defaults */
  103.     for(j=y;j<(x*y)+1;j++){
  104.         per=res[j];
  105.         per/=MAXROLLS;
  106.         per*=100;
  107.         /* I have no idea at all why it refuses to allow me to use 
  108.         1 statement ;-((( */
  109.         maxper-=per;
  110.         minper=100-(maxper+per);
  111.         fprintf(fp,"%d\t%5.3f\t%5.3f\t%5.3f\t\t%d\t",j,per,minper,
  112.            maxper,res[j]);
  113.         for(k=0;k<(int) per+1;k++) putc('*',fp);
  114.         putc('\n',fp);
  115.     }
  116. }
  117. ------------------------------ CUT HERE --------------------------
  118.  
  119. -- 
  120.  
  121.  [=]    [=-=]    [=]
  122.  | |=-=-| c |-=-=| |
  123. _|_|____|_^_|____|_|_
  124.  
  125. (iago@ucscb.ucsc.edu)
  126.